package com.baseweb.webadmin.weixin.jssdk;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.baseweb.webadmin.weixin.sign.ConfingJsSign;
import com.baseweb.webadmin.weixin.utils.Constant;


/**
 * 获取 js  config 签名
 */
//@WebServlet(urlPatterns={"/weixin"})
public class Weixin extends HttpServlet {
	private   static  Logger logeer = Logger.getLogger(Weixin.class);
	private static final long serialVersionUID = 1L; 
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			Map<String, String> ret = ConfingJsSign.getConfingJsSign(request);
			for (Map.Entry entry : ret.entrySet()) {
			    System.out.println(entry.getKey() + ", " + entry.getValue());
			}	
			request.setAttribute("nonceStr", ret.get("nonceStr"));
			request.setAttribute("signature", ret.get("signature"));
			request.setAttribute("timestamp", ret.get("timestamp"));
			request.setAttribute("appid", Constant.WX_APPID);
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		} catch (Exception e) {
			logeer.error("获取config js签名时出现异常",e);
		}
		
	}

	public  void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
		
	}	   
}
